package com.app.mymusic.model;

import android.content.Context;

import com.app.mymusic.db.MySqlOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.QueryBuilder;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/10.
 */
public class Mp3InfoDao {

    private  MySqlOpenHelper helper;
    private Dao<Mp3Info,Integer> mp3Dao;
    private QueryBuilder<Mp3Info,Integer> builder;

    public Mp3InfoDao(Context context) {
        helper= MySqlOpenHelper.getMySqlOpenHelper(context);
        try {
            mp3Dao= helper.getUserDao();
            builder=mp3Dao.queryBuilder();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void addMp3Info(Mp3Info mp3Info)
    {
        try {
            mp3Dao.create(mp3Info);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void queryByHash()
    {
//        builder.groupBy("hash").query();
    }

    public List<Mp3Info> getAll()
    {
        List<Mp3Info> lists=new ArrayList<Mp3Info>();
        try {
            lists= mp3Dao.queryForAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return lists;
    }
}
